<?php

namespace app\admin\controller;
use think\db;
use think\Controller;


class BankRules extends Base
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
  public function index()
    {
       $data = input();
       $where = array();
       $list = db("bank_rules")->where($where)->paginate( 2, false, ['query'=>request()->param()] );
       $data = $list->items();
       $this->assign('data',$data);
       $this->assign('list',$list);
       return $this->fetch();
    }
    //银行添加
    public function add()
    {
       if(request()->isPost())
       {
           $inputdata = input();
           $data = array();
           $data['rules'] = $inputdata['rules'];
//           $data['status'] = $inputdata['status'];
           $res = db('bank_rules')->insert($data);
           if($res) {
               $this->success('添加成功','BankRules/index');
           } else {
               $this->error('添加失败');
           }
       } else {
           return $this->fetch();
       }
    }
    public function remove()
    {
        $id= input('id');
        if (db('bank_rules')->where('id',$id)->delete()) {
            $this->success('删除成功',url("/BankRules/index"));
        } else {
            $this->error('删除失败');
        }
    }
    //银行修改
    public function edit()
    {
        $id = input('id');
        if(request()->isPost()) {
            $inputdata = input();
            $data['rules'] = $inputdata['rules'];
            
            $bol = db('bank_rules')->where(['id'=>$id])->update($data);
            if($bol) {
                $this->success('编辑成功','BankRules/index');
            } else {
                $this->success('编辑失败');
            }
        } else {
            $list=db('bank_rules')->where(['id'=>$id])->find();
            $this->assign('list',$list);
            return $this->fetch();
        }
    }
}
